﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using Wise.Util;

namespace UnitTestProject1
{
    [TestClass]
    public class TestOther
    {
        [TestMethod]
        public void Test()
        {
            string input = "20160318";
            DateTime dt = YYYYMMDD(input, null);
            Assert.AreEqual(input, dt.ToString("yyyyMMdd"));
        }
        public static DateTime YYYYMMDD(object val, DataRow _row)
        {
            string strVal = val.ToString();
            return NullHelper.IsDbNull(val)
                ? new DateTime(1900, 1, 1)
                : DateTime.Parse((strVal.Insert(4, "-").Insert(7, "-")));
        }

        [TestMethod]
        public void Test1()
        {
            List<int> myDatas = new List<int>() { 1, 2, 3, 4, 5, 6 };
            {
                Stack<int> lst = new Stack<int>(myDatas);
                int v = lst.Pop();
                Assert.AreEqual(6, v);
                Assert.AreEqual(5, lst.Count);
            }
            {
                Queue<int> lst = new Queue<int>(myDatas);
                int val = lst.Dequeue();
                Assert.AreEqual(1, val);
                Assert.AreEqual(5, lst.Count);
            }
        }

        [TestMethod]
        public void Test3()
        {
            byte[] bb = Encoding.UTF8.GetBytes("0123");
            string hex = Convert.ToBase64String(bb);
            using (SqlConnection con = new SqlConnection(DbHelper.GetConnectionString()))
            {
                con.Open();
                using (var cmd = con.CreateCommand())
                {
                    cmd.CommandText = "INSERT INTO MYBUffer(Buffer)Values(CONVERT())";
                }
            }
        }

        [TestMethod]
        public void Test2()
        {
            Regex reg = new Regex(@" ^[\w|\d|\s]+$", RegexOptions.Multiline| RegexOptions.Compiled);
            {
                bool flag = reg.IsMatch("我是一条龙");
                Assert.AreEqual(true, flag);
            }
            {
                bool flag = reg.IsMatch("我是1条龙");
                Assert.AreEqual(true, flag);
            }
            {
                bool flag = reg.IsMatch("HDISTRICT +'  '+ HAREA");
                Assert.AreEqual(false, flag);
            }
        }
    }
}
